﻿using LanqiQAwebapi.Interface;
using LanqiQAwebapi.Models;

namespace LanqiQAwebapi.Todo
{
    public class commnets : Icomments
    {
        private readonly LanQiQaDBContext _lanQiQaDBContext;
        private readonly ICacheService _cacheService;
        public commnets(LanQiQaDBContext lanQiQaDBContext, ICacheService cacheService)
        {
            _lanQiQaDBContext = lanQiQaDBContext;
            _cacheService = cacheService;

        }
        public void AddComment(int essayid, int userid, string commnet)
        {

         var data=   _lanQiQaDBContext.Comments.Where(o => o.AnswerId == essayid).ToList();

            Comment comment = new Comment()
            {
                AnswerId = essayid,
                UserId = userid,
                Comment1 = commnet,
                    UpvoteCount = 0

            };

            _lanQiQaDBContext.Comments.Add(comment);


           
        }

        public void AddCommentByUser(int essayid, int userid, string commnet, string commentbyuserid)
        {
            var data = _lanQiQaDBContext.Comments.Where(o => o.AnswerId == essayid).ToList();

            Comment comment = new Comment()
            {
                AnswerId = essayid,
                UserId = userid,
                Comment1 = commnet,
                UpvoteCount = 0,
               /* Commnettouser= commentbyuserid*/
            };

            _lanQiQaDBContext.Comments.Add(comment);
        }

        public List<Comment> GetCommentsByEssayId(int page, int pagesize , int essayid)
        {

            var query = _lanQiQaDBContext.Comments.Where(o=>o.AnswerId==essayid).AsQueryable();


            return query.Skip((page - 1) * pagesize).Take(page).ToList();
        }
    }
}
